using System;
using System.Collections;

using LocalBoard.Domain;
using LocalBoard.Persistence;

namespace LocalBoard.Controller
{
	/// <summary>
	/// Summary description for MessageController.
	/// </summary>
	public class MessageController
	{
		protected int _messageId;
		protected Message _message;
		protected IAccessorFactory _accessorFactory;

		public MessageController(int messageId, IAccessorFactory accessorFactory)
		{
			if(accessorFactory == null)
				throw new ArgumentException("", "accessorFactory");
			_messageId = messageId;
			_accessorFactory = accessorFactory;
			_message = _accessorFactory.GetMessageAccessor().Get(_messageId);
		}

		public MessageController(Message message, IAccessorFactory accessorFactory)
		{
			if(message == null)
				throw new ArgumentException("", "message");
			if(accessorFactory == null)
				throw new ArgumentException("", "accessorFactory");
			_messageId = message.Id;
			_message = message;
			_accessorFactory = accessorFactory;
		}

		public int PostComment(string commentBody, Profile user)
		{
			return _accessorFactory.GetCommentAccessor().Insert(new Comment(commentBody, user.UserName, user.UserId, user), _messageId);
		}

		public void DeleteComment(int commentId)
		{
			_accessorFactory.GetCommentAccessor().Delete(commentId);
		}

		public void UploadAttachment(Attachment attachment)
		{
			_accessorFactory.GetAttachmentAccessor().Insert(attachment, _messageId);
		}

		public void DeleteAttachment(int attachmentId)
		{
			_accessorFactory.GetAttachmentAccessor().Delete(attachmentId);
		}
	}
}
